<?php
	include_once "../classes/khoahoc_bs.php";
	include_once "../classes/lophoc_bs.php";
	include_once "../classes/hocvien_bs.php";
	include_once "../classes/phonghoc_bs.php";
	$KhoaHoc = new khoahoc_bs();
	$KhoaHoc->SetMaTrangThai(1);
	$DKhoaHoc = $KhoaHoc->LayDanhSach(); //Lấy danh sách các khóa học và lấy 2 khóa gần nhất
	
	if($DKhoaHoc != null)
	{
?>

	<table width="98%" style="margin: 0 auto">
		<tr>
			<th colspan="2"><?php echo $DKhoaHoc[0]['TenKhoaHoc']; ?></th>
		</tr>
		<?php
			$MK = $DKhoaHoc[0]['MaKhoaHoc'];
			$LopHoc = new lophoc_bs();
			$LopHoc->SetMaKhoaHoc($MK);
			$DLopHoc = $LopHoc->LayDanhSach();
			if($DLopHoc == null)
				echo '<tr><td align="center">-</td></tr>';
			else
				for($i = 0; $i < count($DLopHoc); $i++)
				{
					$HocVien = new hocvien_bs();
					$HocVien->SetMaLopHoc($DLopHoc[$i]['MaLopHoc']);
					$DHocVien = $HocVien->LayDanhSach();
					$SoHocVien = $DHocVien == null ? 0 : count($DHocVien);
					
					$PhongHoc = new phonghoc_bs();
					$PhongHoc->SetMaPhong($DLopHoc[$i]['MaPhong']);
					$DPhongHoc = $PhongHoc->LayDanhSach();
					$Max = $DPhongHoc == null ? 0 : $DPhongHoc[0]['SoMayHoatDong'];
					
					echo '<tr>';
						echo '<td width="60%"><a href="index.php?act=hocvien_danhsachlop&mlh=' . $DLopHoc[$i]['MaLopHoc'] . '">' . $DLopHoc[$i]['MaLopHoc'] . '</a></td>';
						echo '<td><a href="index.php?act=hocvien_danhsachlop&mlh=' . $DLopHoc[$i]['MaLopHoc'] . '">' . $SoHocVien . '/' . $Max . '</a></td>';
					echo '</tr>';
				}
		?>
	</table>
	<?php
		if(count($DKhoaHoc) > 1)
		{
	?>
			<table width="98%" style="margin: 0 auto">
				<tr>
					<th colspan="2"><?php echo $DKhoaHoc[1]['TenKhoaHoc']; ?></th>
				</tr>
				<?php
					$MK = $DKhoaHoc[1]['MaKhoaHoc'];
					$LopHoc = new lophoc_bs();
					$LopHoc->SetMaKhoaHoc($MK);
					$DLopHoc = $LopHoc->LayDanhSach();
					if($DLopHoc == null)
						echo '<tr><td align="center">-</td></tr>';
					else
						for($i = 0; $i < count($DLopHoc); $i++)
						{
							if($DLopHoc[$i]['MaLopHoc'] != "0")
							{
								$HocVien = new hocvien_bs();
								$HocVien->SetMaLopHoc($DLopHoc[$i]['MaLopHoc']);
								$DHocVien = $HocVien->LayDanhSach();
								$SoHocVien = $DHocVien == null ? 0 : count($DHocVien);
								
								$PhongHoc = new phonghoc_bs();
								$PhongHoc->SetMaPhong($DLopHoc[$i]['MaPhong']);
								$DPhongHoc = $PhongHoc->LayDanhSach();
								$Max = $DPhongHoc == null ? 0 : $DPhongHoc[0]['SoMayHoatDong'];
								
								echo '<tr>';
									echo '<td width="60%"><a href="index.php?act=hocvien_danhsachlop&mlh=' . $DLopHoc[$i]['MaLopHoc'] . '">' . $DLopHoc[$i]['MaLopHoc'] . '</a></td>';
									echo '<td><a href="index.php?act=hocvien_danhsachlop&mlh=' . $DLopHoc[$i]['MaLopHoc'] . '">' . $SoHocVien . '/' . $Max . '</a></td>';
								echo '</tr>';
							}
						}
				?>
			</table>

<?php
		}
	}
?>